package com.jiang.smartdangjian.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.jiang.smartdangjian.R;

public class S3DActivity extends BaseActivity implements View.OnClickListener {

    private EditText editTextTextPersonName3;
    private TextView textView38;
    private TextView textView39;
    private ImageView imageView18;
    private Button button4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_s3_d);
        initView();
        setTitle("反馈");
    }

    private void initView() {
        editTextTextPersonName3 = (EditText) findViewById(R.id.editTextTextPersonName3);
        textView38 = (TextView) findViewById(R.id.textView38);
        textView39 = (TextView) findViewById(R.id.textView39);
        imageView18 = (ImageView) findViewById(R.id.imageView18);
        button4 = (Button) findViewById(R.id.button4);

        button4.setOnClickListener(this);

        editTextTextPersonName3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                textView39.setText("" + s.length());
            }
        });
        imageView18.setOnClickListener(v -> {
            startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"), 888);
        });
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        try {
            Uri data1 = data.getData();

            imageView18.setImageURI(data1);
        } catch (Exception e) {
            toast(e.getMessage());
        }

        super.onActivityResult(requestCode, resultCode, data);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button4:
                submit();
                break;
        }
    }

    private void submit() {
        // validate
        String editTextTextPersonName3String = editTextTextPersonName3.getText().toString().trim();
        if (TextUtils.isEmpty(editTextTextPersonName3String)) {
            Toast.makeText(this, "内容不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        toast("提交成功");
        finish();


    }
}